package com.atguigu.myjuc.cas;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * cas=>比较并替换
 * 内存位置  预期原值  更新值
 */
public class CasHello {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(3);

        System.out.println(atomicInteger.get());
        //这里3是期望值，13是更新值
        System.out.println(atomicInteger.compareAndSet(3, 13)+"\t"+atomicInteger.get());
        System.out.println(atomicInteger.compareAndSet(3, 23)+"\t"+atomicInteger.get());
        System.out.println(atomicInteger.incrementAndGet());//++i   14
        System.out.println(atomicInteger.getAndIncrement() + "\t" + atomicInteger.get()); //i++
        System.out.println(atomicInteger.addAndGet(3));
    }
}
